package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.dto.AdminOrderLikeDTO;
import cn.scxy.bookcity.pojo.entity.Orders;
import cn.scxy.bookcity.pojo.vo.AdminOrdersGoodsListVO;
import cn.scxy.bookcity.pojo.vo.AdminOrdersListVO;
import cn.scxy.bookcity.pojo.vo.HotSearchListVO;
import cn.scxy.bookcity.service.IAdminOrderService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/adminorders")
@Api(tags = "管理员订单管理")
@Slf4j
public class AdminOrdersController {
    @Autowired
    private IAdminOrderService service;
    @ApiOperation("查询订单列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/list")
    public JsonResult<List<AdminOrdersListVO>> selectOrderList() {
        List<AdminOrdersListVO> list = service.selectOrderList();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询未付款订单列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/notpaylist")
    public JsonResult<List<AdminOrdersListVO>> notPayList() {
        List<AdminOrdersListVO> list = service.notPayList();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询付款订单列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/paylist")
    public JsonResult<List<AdminOrdersListVO>> PayList() {
        List<AdminOrdersListVO> list = service.PayList();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询发货订单列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/deliverList")
    public JsonResult<List<AdminOrdersListVO>> deliverList() {
        List<AdminOrdersListVO> list = service.deliverList();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询收货订单列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/Receipt")
    public JsonResult<List<AdminOrdersListVO>> Receipt() {
        List<AdminOrdersListVO> list = service.receiptList();
        return JsonResult.ok(list);
    }


    @ApiOperation("查询订单对应的商品列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/goodslist/{id}")
    public JsonResult<List<AdminOrdersGoodsListVO>> selectGoodsList(@PathVariable Long id) {
        List<AdminOrdersGoodsListVO> list = service.selectGoodsList(id);
        return JsonResult.ok(list);
    }
    @ApiOperation("统计订单未发货数量")
    @ApiOperationSupport(order = 301)
    @GetMapping("/selectOrderCount")
    public JsonResult<Integer> selectOrderCount() {
        int i= service.selectOrderCount();
        return JsonResult.ok(i);
    }
    @ApiOperation("模糊查询")
    @ApiOperationSupport(order = 301)
    @PostMapping("/selectLikeOrders")
    public JsonResult<List<AdminOrdersListVO>> selectLikeOrders(AdminOrderLikeDTO adminOrderLikeDTO) {
        System.out.println("adminOrderLikeDTO = " + adminOrderLikeDTO.toString());
        List<AdminOrdersListVO> list = service.selectLikeOrders(adminOrderLikeDTO);
        return JsonResult.ok(list);
    }




//    -----------------------------------------------------------------------------------------------------------------------
    @ApiOperation("支付订单")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/pay")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("开始处理【支付】的请求，参数：{}", id);
        service.setPay(id);
        return JsonResult.ok();
    }

    @ApiOperation("未支付订单")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/notpay")
    public JsonResult<Void> notpay(@PathVariable Long id) {
        log.debug("开始处理【支付】的请求，参数：{}", id);
        service.setNotpay(id);
        return JsonResult.ok();
    }
    @ApiOperation("发货订单")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/deliver")
    public JsonResult<Void> setDeliver(@PathVariable Long id) {
        log.debug("开始处理【发货】的请求，参数：{}", id);
        service.setDeliver(id);
        return JsonResult.ok();
    }
    @ApiOperation("收货订单")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "long")
    @PostMapping("/state/{id:[0-9]+}/receipt")
    public JsonResult<Void> setReceipt(@PathVariable Long id) {
        log.debug("开始处理【收货】的请求，参数：{}", id);
        service.setReceipt(id);
        return JsonResult.ok();
    }



}
